package com.yu.footballpromotionliveadmin.service.impl;

import com.yu.footballpromotionliveadmin.dao.ActivityTypeDao;
import com.yu.footballpromotionliveadmin.dto.DTO;
import com.yu.footballpromotionliveadmin.dto.MessageEnum;
import com.yu.footballpromotionliveadmin.page.PageInfo;
import com.yu.footballpromotionliveadmin.pojo.ActivityType;
import com.yu.footballpromotionliveadmin.service.ActivityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ActivityTypeServiceImpl implements ActivityTypeService {


    @Autowired
    ActivityTypeDao activityTypeDao;


    @Override
    public DTO<ActivityType> getAllActivityTypes() throws Exception {
        List<ActivityType> activityTypes = activityTypeDao.getAllActivityTypes();
        //isPresent表示判断不为空成立则dto为？与：之间的对象
        MessageEnum messageEnum = Optional.ofNullable(activityTypes).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;

        return new DTO<ActivityType>(messageEnum.getCode(),messageEnum.getMessage(),activityTypes);
    }


    @Override
    public DTO<ActivityType> getActivityTypeById(String actno) throws Exception {

        ActivityType activityType = activityTypeDao.getActivityTypeByUno(actno);

        MessageEnum messageEnum = Optional.ofNullable(activityType).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;
        return new DTO<ActivityType>(messageEnum.getCode(),messageEnum.getMessage(),activityType);
    }


    @Override
    public DTO<ActivityType> deleteActivityType(String actno) throws Exception {
        Integer integer = activityTypeDao.deleteActivityType(actno);
        MessageEnum messageEnum = integer > 0 ? MessageEnum.DELETEADMINSUCCESS : MessageEnum.DELETEADMINFAIL;
        return new DTO<ActivityType>(messageEnum.getCode(),messageEnum.getMessage());
    }


    @Override
    public DTO<ActivityType> updateActivityType(ActivityType activityType) throws Exception {

        Integer integer = activityTypeDao.updateActivityType(activityType);

        MessageEnum messageEnum = integer > 0 ? MessageEnum.UPDATEADMINSUCCESS : MessageEnum.UPDATEADMINFAIL;
        return new DTO<ActivityType>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<ActivityType> addActivityType(ActivityType activityType) throws Exception {
        Integer integer = activityTypeDao.addActivityTypeByUno(activityType);
        MessageEnum messageEnum = integer > 0 ? MessageEnum.ADDADMINSUCCESS : MessageEnum.ADDADMINFAIL;
        return new DTO<ActivityType>(messageEnum.getCode(),messageEnum.getMessage(),activityType);
    }

    @Override
    public DTO<ActivityType> getActivityTypesByPage(PageInfo pageInfo) throws Exception {
        List<ActivityType> activityTypesByPage = activityTypeDao.getActivityTypesByPage(pageInfo);
        MessageEnum messageEnum = Optional.ofNullable(activityTypesByPage).isPresent() ? MessageEnum.GETADMINSUCCESS : MessageEnum.GETADMINFAIL;

        return new DTO<ActivityType>(messageEnum.getCode(),messageEnum.getMessage(),activityTypesByPage);
    }

    @Override
    public DTO<ActivityType> getActivityTypesWithOrders(String actno) throws Exception {
        return null;
    }

    @Override
    public DTO<ActivityType> activate(String actno) throws Exception {
        return null;
    }

    @Override
    public DTO<ActivityType> lettory(String actno, String giftName) throws Exception {
        return null;
    }
}
